from flask import Flask, render_template, url_for

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/resources')
def resource_list():
    # 在视图函数中生成 URL
    resources = [
        {"id": 1, "title": "食道", "type": "text", "content": "", "thumbnail": None},
        {"id": 2, "title": "胃", "type": "text", "content": "", "thumbnail": None},
        {"id": 3, "title": "小肠", "type": "text", "content": "", "thumbnail": None},
        {"id": 4, "title": "大肠", "type": "text", "content": "", "thumbnail": None},
        {"id": 5, "title": "肝脏、胆囊、胰脏", "type": "text", "content": "", "thumbnail": None}
    ]
    return render_template('resource_list.html', resources=resources)

@app.route('/resource/<int:resource_id>')
def resource_detail(resource_id):
    # 在这里获取资源数据
    with open("templates/shidao.html") as sd:
        shidao = sd.read()
    with open("templates/wei.html") as w:
        wei = w.read()
    with open("templates/dachang.html") as dc:
        dachang = dc.read()
    with open("templates/xiaochang.html") as xc:
        xiaochang = xc.read()
    with open("templates/ganzang.html") as gz:
        ganzang = gz.read()
    resources = [
        {"id": 1, "title": "食道", "type": "text", "content": shidao},
        {"id": 2, "title": "胃", "type": "text", "content": wei},
        {"id": 3, "title": "小肠", "type": "text", "content": xiaochang},
        {"id": 4, "title": "大肠", "type": "text", "content": dachang},
        {"id": 5, "title": "肝脏、胆囊、胰脏", "type": "text", "content": ganzang}
    ]
    resource = next((r for r in resources if r['id'] == resource_id), None)
    return render_template('resource_detail.html', resource=resource)

if __name__ == '__main__':
    app.run(debug=True, host="0.0.0.0", port=80)
